Reactive Python
The pyr"
macro is just like the py"
macro from PyCall.jl
, except it is reactive! This means:
If you define a Python variable, then other cells that use that python variable are also evaluated.
The scope of Python variables is cleaned up automatically.
Multiple definitions are not allowed.
This is using the Python port of Pluto.ExpressionExplorer by Mikołaj Bochenski: https://github.com/lightning-notebook/engine and some Julia macro magic.
2
4
123123
0.9092974268256817
MethodError: objects of type Nothing are not callable
Here is what happened, the most recent locations are first:
Expr
head: Symbol macrocall
args: Array{Any}((3,))
1: Symbol @py_str
2: LineNumberNode
line: Int64 1
file: Symbol /home/runner/work/disorganised-mess/disorganised-mess/reactive python.jl#==#6449e96f-19ce-4100-8b35-56113bc24b7d
3: String "[1+1]"
Expr
head: Symbol macrocall
args: Array{Any}((3,))
1: Symbol @py_str
2: LineNumberNode
line: Int64 1
file: Symbol /home/runner/work/disorganised-mess/disorganised-mess/reactive python.jl#==#d9bc5dc1-67b6-47c6-9592-3b474ec451a0
3: String "[1+1]\n"
PyObject frozenset()
PyObject frozenset({'x'})
"x"
quote
#= /home/runner/work/disorganised-mess/disorganised-mess/reactive python.jl#==#5c432b4e-60e0-4288-8d5a-42e364ce8d16:8 =#
begin
#= /home/runner/work/disorganised-mess/disorganised-mess/reactive python.jl#==#5c432b4e-60e0-4288-8d5a-42e364ce8d16:12 =#
let s = var"py#var_b"
#= /home/runner/work/disorganised-mess/disorganised-mess/reactive python.jl#==#5c432b4e-60e0-4288-8d5a-42e364ce8d16:13 =#
begin
#= /home/runner/work/disorganised-mess/disorganised-mess/reactive python.jl#==#b9903477-5070-43eb-82a9-8b750f79c8fa:25 =#
var"#471#m" = Main.workspace#4.pynamespace(Main.workspace#4.Main)
#= /home/runner/work/disorganised-mess/disorganised-mess/reactive python.jl#==#b9903477-5070-43eb-82a9-8b750f79c8fa:26 =#
begin
var"#471#m"["__julia_localvar_25_1"] = Main.workspace#4.PyObject(s)
end
#= /home/runner/work/disorganised-mess/disorganised-mess/reactive python.jl#==#b9903477-5070-43eb-82a9-8b750f79c8fa:27 =#
var"#472#ret" = (PyAny)(Main.workspace#4.pyeval_(Base.string("b = __julia_localvar_25_1\n"), var"#471#m", var"#471#m", 257, "/home/runner/work/disorganised-mess/disorganised-mess/reactive python.jl#==#b9903477-5070-43eb-82a9-8b750f79c8fa"))
#= /home/runner/work/disorganised-mess/disorganised-mess/reactive python.jl#==#b9903477-5070-43eb-82a9-8b750f79c8fa:28 =#
nothing
#= /home/runner/work/disorganised-mess/disorganised-mess/reactive python.jl#==#b9903477-5070-43eb-82a9-8b750f79c8fa:29 =#
var"#472#ret"
end
end
end
#= /home/runner/work/disorganised-mess/disorganised-mess/reactive python.jl#==#5c432b4e-60e0-4288-8d5a-42e364ce8d16:19 =#
var"#470#output" = begin
#= /home/runner/work/disorganised-mess/disorganised-mess/reactive python.jl#==#b9903477-5070-43eb-82a9-8b750f79c8fa:25 =#
var"#473#m" = Main.workspace#4.pynamespace(Main.workspace#4.Main)
#= /home/runner/work/disorganised-mess/disorganised-mess/reactive python.jl#==#b9903477-5070-43eb-82a9-8b750f79c8fa:26 =#
begin
end
#= /home/runner/work/disorganised-mess/disorganised-mess/reactive python.jl#==#b9903477-5070-43eb-82a9-8b750f79c8fa:27 =#
var"#474#ret" = (PyAny)(Main.workspace#4.pyeval_((Main.workspace#5.Base).string("x = 123\ny = b\n"), var"#473#m", var"#473#m", 257, "/home/runner/work/disorganised-mess/disorganised-mess/reactive python.jl#==#b9903477-5070-43eb-82a9-8b750f79c8fa"))
#= /home/runner/work/disorganised-mess/disorganised-mess/reactive python.jl#==#b9903477-5070-43eb-82a9-8b750f79c8fa:28 =#
nothing
#= /home/runner/work/disorganised-mess/disorganised-mess/reactive python.jl#==#b9903477-5070-43eb-82a9-8b750f79c8fa:29 =#
var"#474#ret"
end
#= /home/runner/work/disorganised-mess/disorganised-mess/reactive python.jl#==#5c432b4e-60e0-4288-8d5a-42e364ce8d16:23 =#
begin
#= /home/runner/work/disorganised-mess/disorganised-mess/reactive python.jl#==#5c432b4e-60e0-4288-8d5a-42e364ce8d16:27 =#
var"py#var_x" = begin
#= /home/runner/work/disorganised-mess/disorganised-mess/reactive python.jl#==#b9903477-5070-43eb-82a9-8b750f79c8fa:25 =#
var"#475#m" = Main.workspace#4.pynamespace(Main.workspace#4.Main)
#= /home/runner/work/disorganised-mess/disorganised-mess/reactive python.jl#==#b9903477-5070-43eb-82a9-8b750f79c8fa:26 =#
begin
end
#= /home/runner/work/disorganised-mess/disorganised-mess/reactive python.jl#==#b9903477-5070-43eb-82a9-8b750f79c8fa:27 =#
var"#476#ret" = (PyAny)(Main.workspace#4.pyeval_(Base.string("x"), var"#475#m", var"#475#m", 258, "/home/runner/work/disorganised-mess/disorganised-mess/reactive python.jl#==#b9903477-5070-43eb-82a9-8b750f79c8fa"))
#= /home/runner/work/disorganised-mess/disorganised-mess/reactive python.jl#==#b9903477-5070-43eb-82a9-8b750f79c8fa:28 =#
begin
end
#= /home/runner/work/disorganised-mess/disorganised-mess/reactive python.jl#==#b9903477-5070-43eb-82a9-8b750f79c8fa:29 =#
var"#476#ret"
end
end
begin
#= /home/runner/work/disorganised-mess/disorganised-mess/reactive python.jl#==#5c432b4e-60e0-4288-8d5a-42e364ce8d16:27 =#
var"py#var_y" = begin
#= /home/runner/work/disorganised-mess/disorganised-mess/reactive python.jl#==#b9903477-5070-43eb-82a9-8b750f79c8fa:25 =#
var"#477#m" = Main.workspace#4.pynamespace(Main.workspace#4.Main)
#= /home/runner/work/disorganised-mess/disorganised-mess/reactive python.jl#==#b9903477-5070-43eb-82a9-8b750f79c8fa:26 =#
begin
end
#= /home/runner/work/disorganised-mess/disorganised-mess/reactive python.jl#==#b9903477-5070-43eb-82a9-8b750f79c8fa:27 =#
var"#478#ret" = (PyAny)(Main.workspace#4.pyeval_(Base.string("y"), var"#477#m", var"#477#m", 258, "/home/runner/work/disorganised-mess/disorganised-mess/reactive python.jl#==#b9903477-5070-43eb-82a9-8b750f79c8fa"))
#= /home/runner/work/disorganised-mess/disorganised-mess/reactive python.jl#==#b9903477-5070-43eb-82a9-8b750f79c8fa:28 =#
begin
end
#= /home/runner/work/disorganised-mess/disorganised-mess/reactive python.jl#==#b9903477-5070-43eb-82a9-8b750f79c8fa:29 =#
var"#478#ret"
end
end
#= /home/runner/work/disorganised-mess/disorganised-mess/reactive python.jl#==#5c432b4e-60e0-4288-8d5a-42e364ce8d16:31 =#
var"#470#output"
end
3
0.747367
nothing
123
1123124
UndefVarError: @pyr_str not defined
Here is what happened, the most recent locations are first:
- from :0
- #macroexpand#51from expr.jl:117
- from This cell: line 1
Base.remove_linenums!(Meta.macroexpand(@__MODULE__, :(pyr"""
x = 123
@pyr_str (macro with 1 method)
@pyr_old_str (macro with 1 method)
2
@custom_py_str (macro with 1 method)
Following code is from https://github.com/lightning-notebook/engine/blob/master/tests/testvariableaccess.py
PyObject <function reads_writes at 0x7fd600fd87c0>